﻿using LightingPlatform.Tools;
using LightingPlatform.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace LightingPlatform.View
{
    public partial class LightingNavigation : UserControl, IPageProvider
    {
        public LightingNavigation()
        {
            InitializeComponent();

            Pictures.ItemsSource = LightingTypeProvider.LightingTypes;
            Pictures.SelectionChanged += Pictures_SelectionChanged;
        }

        private void Pictures_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            LightingType lightingType = (LightingType)Pictures.SelectedItem;
            if (lightingType == null)
                return;

            CondProdClass.Builder builder = new CondProdClass.Builder();

            bool hasParameter = false;
            if (lightingType.UsePlace > 0)
            {
                builder.SetUsePlace(lightingType.UsePlace);
                hasParameter = true;
            }

            if (lightingType.Setup > 0)
            {
                builder.SetSetup(lightingType.Setup);
                hasParameter = true;
            }

            if (lightingType.Class > 0)
            {
                builder.SetClass(lightingType.Class);
                hasParameter = true;
            }

            CondProdClass parameter = builder.Build();
            if (hasParameter)
            {
                BusinessContext.Singleton.QueryParameters.Push(parameter);
                Navigation.Navigate(new Uri("/View/Level2/LightingClassView.xaml", UriKind.RelativeOrAbsolute));
            }
            else
            {
                MessageHelper.ShowMessage("该操作未实现！");
            }
        }

        public PageLevel PageLevel
        {
            get { return PageLevel.First; }
        }


        public Frame Navigation
        {
            get;
            set;
        }
    }
}
